package com.lenovo.dll.nebula.vod.parse.service;

import java.io.IOException;
import java.net.SocketTimeoutException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.xml.parsers.ParserConfigurationException;

//import org.apache.http.NameValuePair;
//import org.apache.http.message.BasicNameValuePair;
import org.xml.sax.SAXException;

import com.lenovo.dll.nebula.vod.detail.Constant;
import com.lenovo.dll.nebula.vod.parse.handler.IHandler;
import com.lenovo.dll.nebula.vod.parse.service.IPlayUrlService;

public class PlayUrlService<T> implements IPlayUrlService<T>{
	
	private IHandler<T> mHandler = null;
	
	public PlayUrlService(IHandler<T> handler){
		mHandler = handler;
	}
	
	@Override
	public T getPlayUrl(int itemType, String itemCode, String videoCode) throws ParserConfigurationException, SAXException, IOException {
		
		Map<String,String> params = getDefaultParams();
		params.put(Constant.PARAM_ITEM_TYPE, String.valueOf(itemType));
		params.put(Constant.PARAM_ITEM_CODE, itemCode);
		params.put(Constant.PARAM_CLIP_CODE, videoCode);
		List<T> t=mHandler.getEntities(params, Constant.PLAY_URL);
		return t.get(0);
		/*
		List<NameValuePair> params = getDefaultParams();
		params.add(new BasicNameValuePair(Constant.PARAM_ITEM_TYPE, String.valueOf(itemType)));
		params.add(new BasicNameValuePair(Constant.PARAM_ITEM_CODE, itemCode));
		params.add(new BasicNameValuePair(Constant.PARAM_CLIP_CODE, videoCode));
		String result=super.doPost(params, Constant.PLAY_URL);
		if(result!=null){
			return mHandler.getEntities(result);
		}else{
			System.out.println("getEntities error");
			return null;
		}*/
	}
	
	private Map<String,String> getDefaultParams(){
		
		Map<String,String> defaultParams = new HashMap<String,String>();
		defaultParams.put(Constant.PARAM_USER_ID, Constant.VALUE_USER_ID);
		defaultParams.put(Constant.PARAM_USER_GROUP, Constant.VALUE_USER_GROUP);
		defaultParams.put(Constant.PARAM_USER_TOKEN, Constant.VALUE_USER_TOKEN);
		defaultParams.put(Constant.PARAM_SERVICE_TYPE, "1");
		defaultParams.put(Constant.PARAM_TERMINAL_KIND, "4");
		return defaultParams;
	}
	
	
	/*
	private List<NameValuePair> getDefaultParams(){
		List<NameValuePair> httpParams = new ArrayList<NameValuePair>();	
		httpParams.add(new BasicNameValuePair(Constant.PARAM_USER_ID, Constant.VALUE_USER_ID));	
		httpParams.add(new BasicNameValuePair(Constant.PARAM_USER_GROUP, Constant.VALUE_USER_GROUP));
		httpParams.add(new BasicNameValuePair(Constant.PARAM_USER_TOKEN, Constant.VALUE_USER_TOKEN));
		httpParams.add(new BasicNameValuePair(Constant.PARAM_SERVICE_TYPE, "1"));
		httpParams.add(new BasicNameValuePair(Constant.PARAM_TERMINAL_KIND, "4"));
		return httpParams;
	}*/

}